/*
 * @Author: yangzonglong
 * @Date: 2021-03-05 12:08:36
 * @version: v1.0.0
 * @Descripttion:
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2021-08-31 09:47:44
 * @Auditor:
 */
import React, { useEffect, useState } from 'react';
import PrintItem from './../PrintItem';

const App = (props) => {
  const { formItemProps, initialValue, inputProps } = props;

  const [value, setValue] = useState(undefined);

  useEffect(() => {
    if (initialValue && Array.isArray(initialValue)) {
      setValue(initialValue.reduce((all, next) => { return (all + ' ') + (next?.[inputProps.showFieldName] || ''); }, ''));
    } else if (initialValue && typeof initialValue === 'object') {
      setValue([initialValue].reduce((all, next) => { return (all + ' ') + (next?.[inputProps.showFieldName] || ''); }, ''));
    }
  }, [initialValue, inputProps]);

  return (
    <PrintItem
      style={formItemProps?.style || {}}
      label={localStorage.i18nextLng === 'en' ? formItemProps?.labelEn : formItemProps?.label}>
      {value}
    </PrintItem>
  );
};

export default App;
